<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>账单列表</title>
<style type="text/css">
td {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: gray;
	/* background-color: black; */
	table-layout: fixed
}

th {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: orange;
	/* background-color: black; */
	table-layout: fixed
}

.id {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: aqua;
	background-color: black;
}

.t {
	color: green;
	text-decoration: line-through;
}
</style>
<script type="text/javascript">
	function up(n, ye) {
		location.href = "SmtUserRead?b=b&Update=" + n + "&num=" + ye;
	}

	//账单添加
	function add(){
		var name = document.getElementById("iname").value;
		var sex = document.getElementById("isex").value;
		var age = document.getElementById("iage").value;
		var tel = document.getElementById("itel").value;
		var add = document.getElementById("iadd").value;
		var rms = document.getElementById("irms").value;
		var password = document.getElementById("ipassword").value;
		if (name.length == 0 || sex.length == 0
				|| age.length == 0 || tel.length == 0 || add.length == 0
				|| rms.length == 0 || password.length == 0) {
			alert("全部为为必填项!");
		} else {
			if (confirm("确定要添加用户吗？") == true) {
				submit();
			}
		}
		return false;
	}
	function remove(i, n) {
		if (confirm("你确信要删除用户" + n + "吗？") == true) {
			location.href = "SmtUserRemove?Remove=" + i;
		} else {
			alert("取消");
		}
	}
	function adds(n,y) {
		if (n != 3) {
			location.href = "SmtUserRead?add=2&num="+y;
		} else {
			location.href = "SmtUserRead?num="+y;
		}

	}
	function newye(ye) {
		location.href = "SmtUserRead?num="+ye+"&b=b";
	}
	function tiao(ye, yenum) {
		if (ye<1||ye>yenum||ye=="请输入") {
			alert("该页不存在哦");
		} else {
			newye(ye);
		}
	}
	//账单更新
	function update() {
		//alert(document.getElementById("id").innerHTML);
		var name = document.getElementById("name").value;
		var sex = document.getElementById("sex").value;
		var age = document.getElementById("age").value;
		var tel = document.getElementById("tel").value;
		var add = document.getElementById("adds").value;
		var password = document.getElementById("password").value;
		if (name.length == 0 || sex.length == 0
				|| age.length == 0 || tel.length == 0 || add.length == 0 || password.length == 0) {
			alert("全部为为必填项!");
		} else {
			if (confirm("确定要更新用户信息吗？") == true) {
				submit();
			}
		}
		return false;
	}
	function no() {
		location.href = "SmtUserRead";
	}
	function showTime(){
        var tDate = new Date();
        var tseconds = tDate.getSeconds();
        if (tseconds < 10)
            tseconds = '0' + tseconds;
        var timeStr1 = tDate.getFullYear()+"-"+(tDate.getMonth()+1)+"-"+tDate.getDate()+"-";
        var timeStr2 = tDate.getHours() + ':' + tDate.getMinutes() + ':' + tseconds;
        document.getElementById('time1').innerHTML = timeStr1;
        document.getElementById('time2').innerHTML = timeStr2;
        setTimeout(showTime, 1000);
    } 
</script>
</head>
<body bgcolor="#000000" onload="showTime()">
	<c:choose>
		<c:when test="${loginname!=null}">
			<c:if test="${admin!=null}">
				<div class="menu" align="center" style="color: green;">
					<form method="post" action="SmtUserRead">
						用户名称：<input type="text" name="productName" class="input-text"
							value="<c:out value="${productName}" default="" />" />&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" name="submit"
							value="查询" class="button" /> &nbsp;&nbsp;&nbsp;&nbsp; <input
							type="button" value="增加"
							onclick="adds(<c:out value="${add}" default="2"/>,${num});">
					</form>
					<br>
				</div>
			</c:if>

			<form method="post" action="SmtUserUpdate"
				onsubmit="return update();">
				<c:choose>
					<c:when test="${nulls!=null}">
						<td colspan="11"></br>
							<div align="center" style="color: red;">
								${nulls}<br>
							</div></td>
					</c:when>
					<c:otherwise>
						<table cellspacing="1" cellpadding="1" align="center" width="800">
							<tr>
								<th>编号</th>
								<th>名称</th>
								<th>性别</th>
								<th>年龄</th>
								<th>电话</th>
								<th>地址</th>
								<th>权限</th>
								<c:if test="${admin!=null}">
									<th>密码</th>
								</c:if>
							</tr>
							<c:forEach var="l" items="${list}" varStatus="varstatus">
								<c:choose>
									<c:when test="${update==l.id}">
										<tr>
											<td><input type="hidden" name="b" value="b"><input
												type="hidden" name="id" value="${l.id}" /> <input
												type="hidden" name="num" value="${num}" />${l.id}</td>
											<td><input type="text" size="4" id="name" name="name"
												value="${l.name}"
												onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')"></td>
											<td><select name="sex" id="sex">
													<option value="男">男</option>
													<option value="女">女</option>
											</select></td>
											<td><input type="text" id="age" name="age" size="4"
												value="${l.age}" onKeyUp="value=value.replace(/\D/g,'')"></td>
											<td><input type="text" id="tel" name="tel" size="4"
												value="${l.tel}" onKeyUp="value=value.replace(/\D/g,'')"></td>
											<td><input type="text" id="adds" size="4" name="adds"
												value="${l.add}"></td>

											<c:choose>
												<c:when test="${admin==null}">
													<td align="center"><input type="hidden" size="4"
														id="rms" name="rms" value="${l.rms}">${l.rms}</td>
												</c:when>
												<c:otherwise>
													<td align="center"><select name="rms" id="rms">
															<option value="admin">admin</option>
															<option value="user">user</option>
													</select></td>
												</c:otherwise>
											</c:choose>

											<td><input type="password" id="password" name="password"
												size="4" value="${l.password}"
												onKeyUp="value=value.replace(/\D/g,'')"></td>
											<td><input type="submit" value="保存"></td>
											<c:if test="${admin!=null}">
												<td><input type="button" value="删除"
													onclick="remove(${l.id},'${l.name}');"></td>
											</c:if>
										</tr>
									</c:when>
									<c:otherwise>
										<tr>
											<td>${l.id}</td>
											<td>${l.name}</td>
											<td>${l.sex}</td>
											<td>${l.age}</td>
											<td>${l.tel}</td>
											<td>${l.add}</td>
											<td>${l.rms}</td>
											<c:choose>
												<c:when test="${admin==null}">
													<td align="center"></td>
												</c:when>
												<c:otherwise>
													<td>${l.password}</td>
												</c:otherwise>
											</c:choose>
											<td><input type="button" value="修改"
												onclick="up(${l.id},${num});"></td>
											<c:if test="${admin!=null}">
												<td><input type="button" value="删除"
													onclick="remove(${l.id},'${l.name}');"></td>
											</c:if>
										</tr>
									</c:otherwise>
								</c:choose>
							</c:forEach>
					</c:otherwise>
				</c:choose>
				</table>
			</form>

			<c:if test="${add==3}">
				<form action="SmtUserAdd" method="post" onsubmit="return add();">
					<table align="center" cellspacing="1" cellpadding="1" width="800">
						<tr>
							<td align="center"></td>
							<td align="center"><input type="text" size="4" id="iname"
								name="iname" onkeyup="value=value.replace(/[^0-9a-zA-Z]/g,'')" /></td>
							<td align="center"><select name="isex" id="isex">
									<option value="男">男</option>
									<option value="女">女</option>
							</select></td>
							<td align="center"><input type="text" size="4" id="iage"
								name="iage" onKeyUp="value=value.replace(/\D/g,'')"></td>
							<td align="center"><input type="text" size="4" id="itel"
								name="itel" onKeyUp="value=value.replace(/\D/g,'')"></td>
							<td align="center"><input type="text" size="4" id="iadd"
								name="iadd"></td>

							<td align="center"><select name="irms" id="irms">
									<option value="admin">admin</option>
									<option value="user">user</option>
							</select></td>
							<td align="center"><input type="password" size="4"
								id="ipassword" name="ipassword"
								onKeyUp="value=value.replace(/\D/g,'')"></td>
							<td align="center"><input type="submit" size="4" value="提交">
							</td>
							<td align="center"><input type="button" size="4" value="不提交"
								onclick="no()"></td>
						</tr>
					</table>
				</form>
				<br>
			</c:if>
			<c:if test="${error!=null}">
				<br>
				<div align="center" style="color: red;">
					</br>${error}
				</div>
				<br>
			</c:if>
			<hr width="800" align="center">
			<br>
			<table width="300" align="center" cellspacing="1">
				<tr class="3">
					<td>${num}/${yenum}</td>
					<td align="center" valign="middle" class="td"><input
						type="text" id="tiao" size="4"
						onKeyUp="value=value.replace(/\D/g,'')" value="请输入"></td>
					<td align="center" valign="middle" class="td"><input
						type="button" onkeyup="this.value=this.value.replace(/\D/g,'')"
						value="跳转"
						onclick="tiao(document.getElementById('tiao').value,${yenum})">
					</td>
				</tr>
			</table>
			<br>
			<br>
			<table width="600" align="center" cellspacing="1">
				<tr class="3">
					<td align="center" valign="middle" class="td"><input
						type="button" value="首页" onclick="newye(1);"></td>
					<c:choose>
						<c:when test="${num!=1}">
							<td align="center" valign="middle" class="td"><input
								type="button" value="上一页" onclick="newye(${num-1});"></td>
						</c:when>
						<c:otherwise>
							<td align="center" valign="middle" class="t">到头了</td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${num!=yenum}">
							<td align="center" valign="middle" class="td"><input
								type="button" value="下一页" onclick="newye(${num+1});"></td>
						</c:when>
						<c:otherwise>
							<td align="center" valign="middle" class="t">没有了</td>
						</c:otherwise>
					</c:choose>
					<td align="center" valign="middle" class="td"><input
						type="button" value="末页" onclick="newye(${yenum});"></td>
				</tr>
			</table>
		</c:when>
		<c:otherwise>
			<div align="center">
				<a onclick="window.top.location='Login.jsp'<%%>" style="color: red;">权限不足，请到首页登陆！</a>
			</div>
		</c:otherwise>
	</c:choose>
	</br>
	</br>
	<hr width="600">
	<div align="center" style="color: green;">CopyRight ©
		2000-2015第一个小小网站 , All Rights Reserved</div>
	</br>
	<div align="center">
		<div id="time1" align="center"
			style="color: #0000ff; font-size: 18px; display: inline; border-style: double;">
		</div>
		<div id="time2" align="center"
			style="color: #ff0080; font-size: 18px; display: inline; border-style: double;"></div>
	</div>
	</br>
</body>
</html>
